package xml

import groovy.xml.StreamingMarkupBuilder

//使用StreamingMarkupBuilder,可以构建更加高级的xml文档
def builder = new StreamingMarkupBuilder()
builder.encoding = "UTF-8"
def person = {
    mkp.xmlDeclaration()  //声明xml标签
    //mkp.pi(xml: "version='1.0'  encoding='UTF-8'")
    //mkp.declareNamespace(ns:"http://www.ebay.com")
    bookstore {
        book(name:"PythonWeb实战"){
            author "大牛"
            year "2019"
            price 56
        }
        mkp.yieldUnescaped("<!--注释-->")
        book(name:"springboot2.x实战"){
            comment << "这种注释也可以"
            author "大神"
            year 2019
            //mkp.yieldUnescaped,不将<,>等符号转义成&lt;,但是必须直接放在闭包中使用
            price { mkp.yieldUnescaped("<![CDATA[ <=99 ]]>") }
        }
    }
}
new FileWriter("newbook.xml") << builder.bind(person)